package com.edu.exam.enums.assessment;

/**
 * 方案状态枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum SchemeStatus {
    DRAFT("DRAFT", "草稿"),
    PUBLISHED("PUBLISHED", "已发布"),
    IMPLEMENTING("IMPLEMENTING", "实施中"),
    COMPLETED("COMPLETED", "已完成"),
    ARCHIVED("ARCHIVED", "已归档"),
    CANCELLED("CANCELLED", "已取消");

    private final String code;
    private final String description;

    SchemeStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static SchemeStatus fromCode(String code) {
        for (SchemeStatus status : SchemeStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown scheme status code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static SchemeStatus fromDescription(String description) {
        for (SchemeStatus status : SchemeStatus.values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown scheme status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}